package lion.framework.core.conf.anno;

import java.lang.annotation.Annotation;

import org.apache.commons.lang.StringUtils;

import lion.dev.lang.MapJ;
import lion.framework.core.anno.AnnoProcessor;
import lion.framework.core.anno.AnnotationProcessorManager;
import lion.framework.core.anno.IAnnotationProcessor;
import lion.framework.core.conf.ConfigManager;
import lion.framework.core.conf.IConfigLoader;

/**
 * {@link ConfigLoader} anotation Processor
 * 
 * @author lion
 * @email hl_0074@sina.com
 * @date 2015年3月17日
 */
@AnnoProcessor(ConfigLoader.class)
public class ConfigLoaderAnnoProcessor implements IAnnotationProcessor {

	@SuppressWarnings("unchecked")
	@Override
	public void processe(MapJ ctx, Annotation anno) throws Exception {

		ConfigLoader cl = (ConfigLoader) anno;
		String type = cl.value();
		if (StringUtils.isBlank(type)) { return; }

		Class<?> cls = ctx.getE(AnnotationProcessorManager.ANNO_CONTEXT_CLASS);
		if (!IConfigLoader.class.isAssignableFrom(cls)) { return; }

		ConfigManager.registConfigLoader(type, (Class<IConfigLoader>) cls);
	}
}
